package com.gskj.eduservice.controller;


import com.gskj.commonutils.ResultJson;
import com.gskj.eduservice.entity.subject.FirstSubject;
import com.gskj.eduservice.service.IEduSubjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * <p>
 * 课程科目 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2020-05-16
 */
@RestController
@RequestMapping("/eduservice/subject")
@CrossOrigin
public class EduSubjectController {

    @Autowired
    private IEduSubjectService iEduSubjectService;


    /***
     *  添加 课程
     *  通过 上传excel文件，从excel中读取所有课程信息
     *
     * @param file 上传的 excel文件流
     * @return
     */
    @PostMapping(value = "/add/subject")
    public ResultJson addSubject(MultipartFile file) {

        // 获取上传的 excel文件,进行保存
        iEduSubjectService.saveSubject(file, iEduSubjectService);
        return ResultJson.success();
    }

    /***
     *  课程分类列表查询 ： 树形结构
     * @return
     */
    @GetMapping("/get/subject/tree")
    public ResultJson subjetcTreeList() {
        // 查询 所有一级二级分类的集合
        List<FirstSubject> treeSubject = iEduSubjectService.getTreeSubject();
        return ResultJson.success().data("treeList", treeSubject);
    }

}

